<template>
	<view>
		<view class="top-main">
			<view class="card">
				<view class="card-tit">登录</view>
				<view class="input-item">
					<view>账号</view>
					<input v-model="username" placeholder="请输入账号" />
				</view>
				<view class="input-item" style="margin-bottom: 20rpx;">
					<view>密码</view>
					<input type="password" v-model="password" placeholder="请输入密码" />
				</view>
				<navigator url="/pages/resign/resign" hover-class="none" class="btn3">注册账号</navigator>
				<view class="btn" @click="toLogin()">登入</view>
				<view class="btn btn2" @click="toBack()">取消登录</view>
				<!-- <view class="flex align between line">
					<text></text>
					<view>微信登入</view>
					<text></text>
				</view> -->
				<!-- <view class="icon">
					<uni-icons type="weixin" size="60" color="#C23015"></uni-icons>
				</view> -->
				<!-- <image src="../../static/images/login/icon3.png" mode="widthFix" class="icon"></image> -->
			</view>
		</view>
	</view>
</template>
<script>
	import {
		userLogin
	} from '@/api/apiData.js';
	export default {
		data() {
			return {
				statusBarHeight: 20,
				barHeight: 44,
				barWidth: null,
				name: '',
				username: '',
				password: '',
				title: '',
				act: 1
			};
		},
		onLoad(option) {
			let that = this;
			if (option.type == 1) {
				this.title = '公司'
			}
			//通过uni自带api获取手机系统信息
			uni.getSystemInfo({
				success: function(res) {
					// console.log(res)
					that.statusBarHeight = res.statusBarHeight; //手机状态栏高度
					let isiOS = res.system.indexOf('iOS') > -1; //是否为iOS系统
					that.barHeight = !isiOS ? 48 : 44; //导航栏高度，iOS：48，Android：44
					that.barWidth = res.windowWidth - 87; //nabbar可操作宽度 = 屏幕宽度 - 小程序右上角的胶囊宽度（87）
				}
			})
		},
		methods: {
			toAct(e) {
				this.act = e
			},
			toBack() {
				uni.reLaunch({
					url: '/pages/index/index'
				})
			},
			async toLogin() {
				const that = this
				const result = await userLogin({
					username: that.username,
					password: that.password
				})
				if (result.code == 1) {
					uni.showToast({
						title: result.msg,
						icon: 'success',
						mask: true
					});
					uni.setStorageSync('token', 'Dearer '+result.data.token);
					uni.setStorageSync('type', 1);
					uni.navigateBack({
						delta: 1,
						fail(error) {
							uni.reLaunch({
								url: '/pages/index/index'
							})
						}
					})
				} else {
					uni.showToast({
						title: result.msg,
						icon: 'error'
					});
				}
			}
		}
	}
</script>

<style lang="less">
	.tabs {
		font-size: 32rpx;
		font-weight: bold;

		view {
			margin-right: 18rpx;
			position: relative;
			padding: 10rpx 0;
		}

		.act::after {
			content: "";
			position: absolute;
			bottom: 0;
			width: 50%;
			left: 25%;
			height: 9rpx;
			background: #FF6543;
			border-radius: 5rpx;
		}
	}

	.nabbar {
		width: 100%;
		overflow: hidden;
		position: absolute;
		top: 0;
		left: 0;
		z-index: 2;
	}

	.status-bar {
		position: fixed;
		// background: white;
		top: 0;
		left: 0;
		right: 0;
		width: 100%;
		// background-color: #FFFFFF;
		// height: var(--status-bar-height);
		z-index: 999;
		// background-color: #000000;
	}

	.nabbar-box {
		position: absolute;
		top: 0;
		left: 0;
		right: 0;
		width: 100%;
		height: 88rpx;
		// background-color: #000000;
		z-index: 999;
		color: white;
		font-size: 32rpx;
		font-weight: bold;

		.nabbar-cont {
			height: 100%;
			display: flex;
			align-items: center;
			justify-content: center;
			position: relative;

			.icons {
				position: absolute;
				left: 30rpx;
				font-weight: 100;
			}

			image {
				width: 56rpx;
				height: 56rpx;
			}
		}
	}

	.top-main {
		position: relative;

		.top-img {
			width: 100%;
			position: fixed;
			height: 100%;
			top: 0;
			left: 0;
			z-index: -1;
		}

		.logo-view {
			text-align: center;
			margin: 53rpx 0 84rpx;

			.top-logo {
				width: 148rpx;
				height: 156rpx;
			}

			view {
				color: #C80000;
				font-size: 28rpx;
				font-weight: bold;
			}
		}


		.card {
			padding: 50rpx 46rpx;
			position: relative;

			.card-tit {
				font-size: 48rpx;
				font-weight: bold;
				text-align: center;
				color: #FF9008;
				margin-bottom: 30rpx;
			}

			.input-item {
				font-size: 32rpx;
				margin: 60rpx 0;
				padding: 10rpx 0;
				border-bottom: solid 1rpx #CACACA;

				view {
					font-weight: bold;
					margin-bottom: 20rpx;
				}

				image {
					width: 40rpx;
					height: 40rpx;
					margin-right: 40rpx;
				}

				input {
					font-size: 26rpx;
					width: 80%;
				}
			}

			.btn {
				line-height: 80rpx;
				background: #FF9008;
				font-size: 32rpx;
				text-align: center;
				color: white;
				border-radius: 10rpx;
				width: 50%;
				margin: 0 auto;
			}

			.btn2 {
				background: white;
				border: solid 1rpx #FF9008;
				margin-top: 50rpx;
				color: #FF9008;
			}

			.line {
				font-size: 26rpx;
				margin-top: 100rpx;

				text {
					display: block;
					width: 231rpx;
					height: 1rpx;
					background: #CACACA;
				}
			}

			.icon {
				text-align: center;
			}

			.btn3 {
				color: #FF9008;
				font-size: 24rpx;
				text-align: right;
				margin-bottom: 40rpx;
			}
		}
	}
</style>